<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表单校验</title>
    <link rel="stylesheet" href="css/style.css"></link>
</head>
<body>
    <div class="login-form-wrap">
        <h1>黑马程序员</h1>
        <form class="login-form" action="#" id="regist" method="get" autocomplete="off">
            <label>
                <input type="text" id="username" name="username" placeholder="Username..." value="">
            </label>
            <label>
                <input type="password" id="password" name="password" placeholder="Password..." value="">
            </label>
            <input type="button" value="注册">
        </form>
    </div>
</body>
<script>
    document.querySelector("[type='button']").onclick = function(){
        let username = document.querySelector("#username").value;
        if(!/^[a-zA-Z]{4,16}$/.test(username)){
            alert("用户名格式错误");
            return;
        }
        let password = document.querySelector("#password").value;
        if(!/^[0-9]{6}$/.test(password)){
            alert("密码格式错误")
            return;
        }
        document.querySelector("form").submit();
    }
</script>
</html>